﻿using EasyDDD.AdminModule.Domain.AggregateSysAdmin;
using EasyDDD.Infrastructure;
using Microsoft.EntityFrameworkCore;

namespace EasyDDD.AdminModule.Repository
{
    public class SysAdminRepository
        : EasyDDD.Infrastructure.EFCore.Repository.Repository<AdminModuleRepositoryDbContext, SysAdmin, Guid>
        , IRepository<SysAdmin, Guid>
    {
        public SysAdminRepository(AdminModuleRepositoryDbContext DbContext) : base(DbContext)
        {
        }

        public async Task<SysAdmin?> GetWithUserRoles(string username)
        {
            var entity = await this.AsQueryable().Include(e => e.UserRoles).FirstOrDefaultAsync(e => e.UserName == username || e.PhoneNumber == username || e.Email == username);
            //if (entity == null)
            //{
            //    throw new BusinessException("用户名错误！");
            //}
            return entity;
        }
    }
}
